import axios from "axios";

// default settings
const instance = axios.create({
    baseURL: '/api',
    timeout: 5000,
});

// request interceptor
instance.interceptors.request.use(config => {
    console.log(`请求拦截器拦截到: ${config}`);
    return config;
}, err => {
    console.log(`Fail to request api: ${err}`);
    return Promise.reject(err);
});

// response interceptor
instance.interceptors.response.use(res => {
    console.log(res.data);
    return res.data;
}, err => {
    console.log(`Interal server error: ${err}`);
    return Promise.reject(err);
});

export default instance;
